package com.terios.logic.ui;

import java.util.HashMap;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

import com.terios.R;
import com.terios.conts.CommonStrs;
import com.terios.logic.MainService;
import com.terios.logic.Task;

/**
 * HomeActivity.java 2012-9-27 下午12:20:51
 * 
 * @author Wang Tengrui
 */
public class MainActivity extends TabActivity {
	public static final int REFRESH_WEIBO = 1;

	public static final String TAB_HOME = "TabHome";
	public static final String TAB_MSG = "TabMsg";
	public static final String TAB_SEARCH = "TabSearch";
	public static final String TAB_USERDATA = "TabUsreData";
	public static final String TAB_MORESET = "TabMorSet";

	public TabHost tabHost;
	public static RadioGroup indexRadioGroup;

	@SuppressWarnings("static-access")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(getWindow().FEATURE_NO_TITLE);// 取消标题显示
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_tabhost);
		RadioButton radio_button0 = (RadioButton) this.findViewById(R.id.radio_button0);
		radio_button0.setChecked(true);// 默认选中首页
		radio_button0.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						int nowPage = 1;
						HashMap<String, Integer> paramHashMap = new HashMap<String, Integer>();
						paramHashMap.put("nowPage", Integer.valueOf(nowPage));
						paramHashMap.put("pageSize", CommonStrs.MAX_INFO_NUM);
						// 新建加载主页微博任务
						Task task = new Task(CommonStrs.TASK_GET_USER_HOMETIMEINLINE, paramHashMap);
						MainService.allTask.add(task);
						HomeActivity homeActivity = (HomeActivity) MainService.getActivityByName("HomeActivity");
						if (null != homeActivity) {
							ProgressBar title_progressBar = (ProgressBar) homeActivity.findViewById(R.id.title_progressBar);
							title_progressBar.setVisibility(View.VISIBLE);
						}
					}
				});
		tabHost = this.getTabHost();
		
		
		TabSpec home_tabSpec = tabHost.newTabSpec(TAB_HOME).setIndicator(TAB_HOME);
		home_tabSpec.setContent(new Intent(MainActivity.this, HomeActivity.class));// 跳转到HomeActivity
		tabHost.addTab(home_tabSpec);

		TabSpec msg_tabSpec = tabHost.newTabSpec(TAB_MSG).setIndicator(TAB_MSG);
		msg_tabSpec.setContent(new Intent(MainActivity.this, MSGActivity.class));// 跳转到MSGActivity
		tabHost.addTab(msg_tabSpec);

		TabSpec userdate_tabSpec = tabHost.newTabSpec(TAB_USERDATA).setIndicator(TAB_USERDATA);
		userdate_tabSpec.setContent(new Intent(MainActivity.this, UserInfoActivity.class));// 跳转到UserInfoActivity
		tabHost.addTab(userdate_tabSpec);

		TabSpec search_tabSpec = tabHost.newTabSpec(TAB_SEARCH).setIndicator(TAB_SEARCH);
		search_tabSpec.setContent(new Intent(MainActivity.this, SearchActivity.class));// 签跳转到SearchActivity
		tabHost.addTab(search_tabSpec);

		TabSpec moreset_tabSpec = tabHost.newTabSpec(TAB_MORESET).setIndicator(TAB_MORESET);
		moreset_tabSpec.setContent(new Intent(MainActivity.this, MoreSetting.class));// 跳转到MoreSetting
		tabHost.addTab(moreset_tabSpec);

		this.indexRadioGroup = (RadioGroup) this.findViewById(R.id.main_radio);
		indexRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_button0:
					tabHost.setCurrentTabByTag(TAB_HOME);
					break;
				case R.id.radio_button1:
					tabHost.setCurrentTabByTag(TAB_MSG);
					break;
				case R.id.radio_button2:
					tabHost.setCurrentTabByTag(TAB_SEARCH);
					break;
				case R.id.radio_button3:
					tabHost.setCurrentTabByTag(TAB_USERDATA);
					break;
				case R.id.radio_button4:
					tabHost.setCurrentTabByTag(TAB_MORESET);
					break;
				}
			}
		});
	}
}
